﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SQL_Provider;
using System.Data;
using System.Data.SqlClient;
using BusinessEntities;

namespace DataAccess
{
    public class HoSoBA_Adapter
    {
        Provider db;
        public HoSoBA_Adapter()
        {
            db = new Provider();
        }

        public int HoSoBA_Them_NoiTru(HoSoBA_Info info)
        {
            SqlParameter[] para = new SqlParameter[22];
            para[0] = new SqlParameter("@MaBA", info.MaBA);
            para[1] = new SqlParameter("@MaBN", info.MaBN);
            para[2] = new SqlParameter("@NgayNhapVien", info.NgayNhapVien);
            para[3] = new SqlParameter("@HoTen", info.HoTen);
            para[4] = new SqlParameter("@NgaySinh", info.NgaySinh);
            para[5] = new SqlParameter("@Tuoi", info.Tuoi);
            para[6] = new SqlParameter("@GioiTinh", info.GioiTinh);
            para[7] = new SqlParameter("@DanToc", info.DanToc);
            para[8] = new SqlParameter("@NgheNghiep", info.NgheNghiep);
            para[9] = new SqlParameter("@DienThoai", info.DienThoai);
            para[10] = new SqlParameter("@DiaChi", info.DiaChi);
            para[11] = new SqlParameter("@DoiTuong", info.DoiTuong);
            para[12] = new SqlParameter("@TrieuChung", info.TrieuChung);
            para[13] = new SqlParameter("@ChuanDoan", info.ChuanDoan);
            para[14] = new SqlParameter("@YLenh", info.YLenh);
            para[15] = new SqlParameter("@NhomBenh", info.NhomBenh);
            para[16] = new SqlParameter("@NhomMau", info.NhomMau);
            para[17] = new SqlParameter("@DieuTri", info.DieuTri);
            para[18] = new SqlParameter("@PhongBenh", info.PhongBenh);
            para[19] = new SqlParameter("@GiuongBenh", info.GiuongBenh);
            para[20] = new SqlParameter("@MaBS", info.MaBS);
            para[21] = new SqlParameter("@TenBS", info.TenBS);
            return db.Execute_Modify("HoSoBA_Them_NoiTru", para, CommandType.StoredProcedure);
        }

        public int HoSoBA_CapNhat_NoiTru(HoSoBA_Info info)
        {
            SqlParameter[] para = new SqlParameter[22];
            para[0] = new SqlParameter("@MaBA", info.MaBA);
            para[1] = new SqlParameter("@MaBN", info.MaBN);
            para[2] = new SqlParameter("@NgayNhapVien", info.NgayNhapVien);
            para[3] = new SqlParameter("@HoTen", info.HoTen);
            para[4] = new SqlParameter("@NgaySinh", info.NgaySinh);
            para[5] = new SqlParameter("@Tuoi", info.Tuoi);
            para[6] = new SqlParameter("@GioiTinh", info.GioiTinh);
            para[7] = new SqlParameter("@DanToc", info.DanToc);
            para[8] = new SqlParameter("@NgheNghiep", info.NgheNghiep);
            para[9] = new SqlParameter("@DienThoai", info.DienThoai);
            para[10] = new SqlParameter("@DiaChi", info.DiaChi);
            para[11] = new SqlParameter("@DoiTuong", info.DoiTuong);
            para[12] = new SqlParameter("@TrieuChung", info.TrieuChung);
            para[13] = new SqlParameter("@ChuanDoan", info.ChuanDoan);
            para[14] = new SqlParameter("@YLenh", info.YLenh);
            para[15] = new SqlParameter("@NhomBenh", info.NhomBenh);
            para[16] = new SqlParameter("@NhomMau", info.NhomMau);
            para[17] = new SqlParameter("@DieuTri", info.DieuTri);
            para[18] = new SqlParameter("@PhongBenh", info.PhongBenh);
            para[19] = new SqlParameter("@GiuongBenh", info.GiuongBenh);
            para[20] = new SqlParameter("@MaBS", info.MaBS);
            para[21] = new SqlParameter("@TenBS", info.TenBS);
            return db.Execute_Modify("HoSoBA_CapNhat_NoiTru", para, CommandType.StoredProcedure);
        }

        public int HoSoBA_CapNhat_Full(int MaBA, DateTime NgayXuatVien, string QuaTrinhTheoDoi, string QuaTrinhDieuTri, string KetQuaDieuTri)
        {
            SqlParameter[] para = new SqlParameter[5];
            para[0] = new SqlParameter("@MaBA", MaBA);
            para[1] = new SqlParameter("@NgayXuatVien", NgayXuatVien);
            para[2] = new SqlParameter("@QuaTrinhTheoDoi", QuaTrinhTheoDoi);
            para[3] = new SqlParameter("@QuaTrinhDieuTri", QuaTrinhDieuTri);
            para[4] = new SqlParameter("@KetQuaDieuTri", KetQuaDieuTri);
            return db.Execute_Modify("HoSoBA_CapNhat_Full", para, CommandType.StoredProcedure);
        }

        public int HoSoBA_Them_NgoaiTru(HoSoBA_Info info)
        {
            SqlParameter[] para = new SqlParameter[21];
            para[0] = new SqlParameter("@MaBA", info.MaBA);
            para[1] = new SqlParameter("@MaBN", info.MaBN);
            para[2] = new SqlParameter("@NgayNhapVien", info.NgayNhapVien);
            para[3] = new SqlParameter("@HoTen", info.HoTen);
            para[4] = new SqlParameter("@NgaySinh", info.NgaySinh);
            para[5] = new SqlParameter("@Tuoi", info.Tuoi);
            para[6] = new SqlParameter("@GioiTinh", info.GioiTinh);
            para[7] = new SqlParameter("@DanToc", info.DanToc);
            para[8] = new SqlParameter("@NgheNghiep", info.NgheNghiep);
            para[9] = new SqlParameter("@DienThoai", info.DienThoai);
            para[10] = new SqlParameter("@DiaChi", info.DiaChi);
            para[11] = new SqlParameter("@DoiTuong", info.DoiTuong);
            para[12] = new SqlParameter("@TrieuChung", info.TrieuChung);
            para[13] = new SqlParameter("@ChuanDoan", info.ChuanDoan);
            para[14] = new SqlParameter("@YLenh", info.YLenh);
            para[15] = new SqlParameter("@NhomBenh", info.NhomBenh);
            para[16] = new SqlParameter("@NhomMau", info.NhomMau);
            para[17] = new SqlParameter("@DieuTri", info.DieuTri);
            para[18] = new SqlParameter("@HenNgayKham", info.HenNgayKham);
            para[19] = new SqlParameter("@MaBS", info.MaBS);
            para[20] = new SqlParameter("@TenBS", info.TenBS);
            return db.Execute_Modify("HoSoBA_Them_NgoaiTru", para, CommandType.StoredProcedure);
        }

        public int HoSoBA_CapNhat_NgoaiTru(HoSoBA_Info info)
        {
            SqlParameter[] para = new SqlParameter[21];
            para[0] = new SqlParameter("@MaBA", info.MaBA);
            para[1] = new SqlParameter("@MaBN", info.MaBN);
            para[2] = new SqlParameter("@NgayNhapVien", info.NgayNhapVien);
            para[3] = new SqlParameter("@HoTen", info.HoTen);
            para[4] = new SqlParameter("@NgaySinh", info.NgaySinh);
            para[5] = new SqlParameter("@Tuoi", info.Tuoi);
            para[6] = new SqlParameter("@GioiTinh", info.GioiTinh);
            para[7] = new SqlParameter("@DanToc", info.DanToc);
            para[8] = new SqlParameter("@NgheNghiep", info.NgheNghiep);
            para[9] = new SqlParameter("@DienThoai", info.DienThoai);
            para[10] = new SqlParameter("@DiaChi", info.DiaChi);
            para[11] = new SqlParameter("@DoiTuong", info.DoiTuong);
            para[12] = new SqlParameter("@TrieuChung", info.TrieuChung);
            para[13] = new SqlParameter("@ChuanDoan", info.ChuanDoan);
            para[14] = new SqlParameter("@YLenh", info.YLenh);
            para[15] = new SqlParameter("@NhomBenh", info.NhomBenh);
            para[16] = new SqlParameter("@NhomMau", info.NhomMau);
            para[17] = new SqlParameter("@DieuTri", info.DieuTri);
            para[18] = new SqlParameter("@HenNgayKham", info.HenNgayKham);
            para[19] = new SqlParameter("@MaBS", info.MaBS);
            para[20] = new SqlParameter("@TenBS", info.TenBS);
            return db.Execute_Modify("HoSoBA_CapNhat_NgoaiTru", para, CommandType.StoredProcedure);
        }

        public int HoSoBA_Xoa(int MaBA)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBA", MaBA);
            return db.Execute_Modify("HoSoBA_Xoa", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_Kham_All(string MaBS)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBS", MaBS);
            return db.Execute_Table("HoSoBA_Kham_All", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheoMaBS(string MaBS)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBS", MaBS);
            return db.Execute_Table("HoSoBA_TimTheoMaBS", para, CommandType.StoredProcedure);
        }

        public DataTable NhomBenh_All()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("NhomBenh_All", para, CommandType.StoredProcedure);
        }

        public DataTable PhongBenhDT_All()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("PhongBenhDT_All", para, CommandType.StoredProcedure);
        }

        public DataTable GiuongBenhDT_All()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("GiuongBenhDT_All", para, CommandType.StoredProcedure);
        }

        public int PhongBenhDT_CapNhatSLBN(string PhongBenh, int TongSoBN)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@PhongBenh", PhongBenh);
            para[1] = new SqlParameter("@TongSoBN", TongSoBN);
            return db.Execute_Modify("PhongBenhDT_CapNhatSLBN", para, CommandType.StoredProcedure);
        }

        public DataTable PhongBenhDT_TimTheoPhongBenh(string PhongBenh)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@PhongBenh", PhongBenh);
            return db.Execute_Table("PhongBenhDT_TimTheoPhongBenh", para, CommandType.StoredProcedure);
        }

        public DataTable GiuongBenhDT_LayTheoPhongBenh(string phongbenh)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@PhongBenh", phongbenh);
            return db.Execute_Table("GiuongBenhDT_LayTheoPhongBenh", para, CommandType.StoredProcedure);
        }

        public DataTable PhongKham_DSMaBNCho(string phongkham)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@PhongKham", phongkham);
            return db.Execute_Table("PhongKham_DSMaBNCho", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_Kham_TimTheoMaBN(string MaBN)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBN", MaBN);
            return db.Execute_Table("HoSoBA_Kham_TimTheoMaBN", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_Kham_TimTheoMaBA(int MaBA)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBA", MaBA);
            return db.Execute_Table("HoSoBA_Kham_TimTheoMaBA", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_Kham_TimTheoMaBA1(int MaBA)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBA", MaBA);
            return db.Execute_Table("HoSoBA_Kham_TimTheoMaBA1", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_Kham_TimTheoMaBN_NgoaiTru(string MaBN)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBN", MaBN);
            return db.Execute_Table("HoSoBA_Kham_TimTheoMaBN_NgoaiTru", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_Kham_TrongNgay_BS(string MaBS)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBS", MaBS);
            return db.Execute_Table("HoSoBA_Kham_TrongNgay_BS", para, CommandType.StoredProcedure);
        }

        public DataTable PhongBenh_TongBN_DieuTri()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("PhongBenh_TongBN_DieuTri", para, CommandType.StoredProcedure);
        }

        public DataTable PhongKham_TimTheoMaBS(string MaBS)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBS", MaBS);
            return db.Execute_Table("PhongKham_TimTheoMaBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_DSLoad(string MaBS)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBS", MaBS);
            return db.Execute_Table("HoSoBA_DSLoad", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_DSBA_PhongBenh(string PhongBenh)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@PhongBenh", PhongBenh);
            return db.Execute_Table("HoSoBA_DSBA_PhongBenh", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_DSLoad_NgoaiTru(string MaBS)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBS", MaBS);
            return db.Execute_Table("HoSoBA_DSLoad_NgoaiTru", para, CommandType.StoredProcedure);
        }

        // Tìm Kiếm:
        public DataTable HoSoBA_TimTheoMaBA_MaBS(int MaBA, string MaBS)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@MaBS", MaBS);
            para[1] = new SqlParameter("@MaBA", MaBA);
            return db.Execute_Table("HoSoBA_TimTheoMaBA_MaBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheoMaBN_MaBS(int MaBN, string MaBS)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@MaBS", MaBS);
            para[1] = new SqlParameter("@MaBN", MaBN);
            return db.Execute_Table("HoSoBA_TimTheoMaBN_MaBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheoHoTenBN_MaBS(string MaBS, string HoTen)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@MaBS", MaBS);
            para[1] = new SqlParameter("@HoTen", HoTen);
            return db.Execute_Table("HoSoBA_TimTheoHoTenBN_MaBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheoNhomTuoi_MaBS(string MaBS, int t1, int t2)
        {
            SqlParameter[] para = new SqlParameter[3];
            para[0] = new SqlParameter("@MaBS", MaBS);
            para[1] = new SqlParameter("@t1", t1);
            para[2] = new SqlParameter("@t2", t2);
            return db.Execute_Table("HoSoBA_TimTheoNhomTuoi_MaBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheoDoiTuong_MaBS(string MaBS, string DoiTuong)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@MaBS", MaBS);
            para[1] = new SqlParameter("@DoiTuong", DoiTuong);
            return db.Execute_Table("HoSoBA_TimTheoDoiTuong_MaBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheoPhongBenh_MaBS(string MaBS, string PhongBenh)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@MaBS", MaBS);
            para[1] = new SqlParameter("@PhongBenh", PhongBenh);
            return db.Execute_Table("HoSoBA_TimTheoPhongBenh_MaBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheoGiuongBenh_MaBS(string MaBS, string GiuongBenh)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@MaBS", MaBS);
            para[1] = new SqlParameter("@GiuongBenh", GiuongBenh);
            return db.Execute_Table("HoSoBA_TimTheoGiuongBenh_MaBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheoNgayNhapVien_MaBS(string MaBS, DateTime NgayNhapVien)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@MaBS", MaBS);
            para[1] = new SqlParameter("@NgayNhapVien", NgayNhapVien);
            return db.Execute_Table("HoSoBA_TimTheoNgayNhapVien_MaBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheoThangNhapVien_MaBS(string MaBS, DateTime NgayNhapVien)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@MaBS", MaBS);
            para[1] = new SqlParameter("@NgayNhapVien", NgayNhapVien);
            return db.Execute_Table("HoSoBA_TimTheoThangNhapVien_MaBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheoNamNhapVien_MaBS(string MaBS, DateTime NgayNhapVien)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@MaBS", MaBS);
            para[1] = new SqlParameter("@NgayNhapVien", NgayNhapVien);
            return db.Execute_Table("HoSoBA_TimTheoNamNhapVien_MaBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheoDieuTri_MaBS(string MaBS, string DieuTri)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@MaBS", MaBS);
            para[1] = new SqlParameter("@DieuTri", DieuTri);
            return db.Execute_Table("HoSoBA_TimTheoDieuTri_MaBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_DangDieuTri_MaBS(string MaBS)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBS", MaBS);
            return db.Execute_Table("HoSoBA_DangDieuTri_MaBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_DaXuatVien_MaBS(string MaBS)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBS", MaBS);
            return db.Execute_Table("HoSoBA_DaXuatVien_MaBS", para, CommandType.StoredProcedure);
        }

        // Tìm Kiếm 2
        public DataTable HoSoBA_TimTheo_MaBS(string MaBS)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@MaBS", MaBS);
            return db.Execute_Table("HoSoBA_TimTheo_MaBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheo_TenBS(string TenBS)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@TenBS", TenBS);
            return db.Execute_Table("HoSoBA_TimTheo_TenBS", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheo_NgayNhapVien(DateTime NgayNhapVien)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@NgayNhapVien", NgayNhapVien);
            return db.Execute_Table("HoSoBA_TimTheo_NgayNhapVien", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheo_ThangNhapVien(DateTime NgayNhapVien)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@NgayNhapVien", NgayNhapVien);
            return db.Execute_Table("HoSoBA_TimTheo_ThangNhapVien", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheo_NamNhapVien(DateTime NgayNhapVien)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@NgayNhapVien", NgayNhapVien);
            return db.Execute_Table("HoSoBA_TimTheo_NamNhapVien", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheo_DangDieuTri()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("HoSoBA_TimTheo_DangDieuTri", para, CommandType.StoredProcedure);
        }

        public DataTable HoSoBA_TimTheo_DaXuatVien()
        {
            SqlParameter[] para = new SqlParameter[0];
            return db.Execute_Table("HoSoBA_TimTheo_DaXuatVien", para, CommandType.StoredProcedure);
        }
    }
}
